package com.msl.base;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;
import com.google.gson.Gson;
import com.msl.R;
import com.msl.dialog.WaitDialog;
import com.msl.scan.BroadcastConfig;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;


//基础Activity
public  class BaseActivity extends Activity {

    //app配置信息
    protected Gson gson = null;
    protected Activity context=null;
    protected WaitDialog waitDialog;
    protected OkHttpClient client;
    protected String result="";
    //protected NetWorkChangReceiver netWorkChangReceiver;

    protected void initBroadcastReciever() {
        // 发送广播到扫描工具内的应用设置项
        Intent intent = new Intent(BroadcastConfig.BROADCAST_SETTING);
        // 修改扫描工具内应用设置中的开发者项下的广播名称
        intent.putExtra(BroadcastConfig.BROADCAST_KEY, BroadcastConfig.CUSTOM_NAME);

//        intent.putExtra(BroadcastConfig.SEND_KEY, "BROADCAST");
//        intent.putExtra(BroadcastConfig.END_KEY, "NONE");

        intent.putExtra(BroadcastConfig.VIBERATE_KEY, false);

        intent.putExtra(BroadcastConfig.SOUND_KEY, true);

        intent.putExtra(BroadcastConfig.CONTINIU_KEY, false);

//        intent.putExtra("interval", 1000);

        sendBroadcast(intent);
    }





    protected BroadcastReceiver mBroadcastReceiverFinish = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context, Intent intent) {
//            if(intent.getAction().equals(Constant.afinish))
//            {
//                finish();
//            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);  // 设置activity显示只能竖屏
        gson = new Gson();
        context = this;
        waitDialog = new WaitDialog(context , R.style.Dialog1);
        WindowManager.LayoutParams lp = waitDialog.getWindow().getAttributes();
        lp.gravity = Gravity.CENTER;
        client = new OkHttpClient.Builder()
                .retryOnConnectionFailure(true)
                .connectTimeout(90, TimeUnit.SECONDS)//设置连接超时时间
                .readTimeout(90, TimeUnit.SECONDS)//设置读取超时时间
                .build();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        unregisterReceiver(netWorkChangReceiver);
//        unregisterReceiver(mBroadcastReceiverFinish);
    }


    @Override
    protected void onResume() {
        super.onResume();
    }


    @Override
    protected void onPause() {
        super.onPause();
    }
}
